#include <stdlib.h>
#include <stdio.h>
#include "../tools/hash_table.h"
#include "../tools/list.h"

#define TEST_MSG(num, status) { printf("Test %d %s\n", num, status); }
#define TEST(num) \
{ \
	if (test ## num()) { TEST_MSG(num, "FAILED"); } \
	else { TEST_MSG(num, "passed"); } \
}

int test1();
int test2();
int test3();

int main()
{
	TEST(1);
	TEST(2);
	TEST(3);
	printf("End of test\n");
	return 0;
}

int test1()
{
	/*construct and destruct*/
	hash_table_t* hash_table = hash_table_construct(200);
	hash_table_destruct(hash_table);
	return 0;
}

int test2()
{
	/*add and find*/
	hash_table_t* hash_table = hash_table_construct(4);
	int value = 0;
	if (hash_table_add(hash_table, 00000, 900000) != 0) return 1;
	if (hash_table_add(hash_table, 11111, 911111) != 0) return 1;
	if (hash_table_add(hash_table, 22222, 922222) != 0) return 1;
	if (hash_table_add(hash_table, 33333, 933333) != 0) return 1;
	if (hash_table_add(hash_table, 33333, 933333) != 1) return 1;
	if (hash_table_find(hash_table, 00000, &value) != 0) return 1;
	if (value != 900000) return 1;
	if (hash_table_find(hash_table, 11111, &value) != 0) return 1;
	if (value != 911111) return 1;
	if (hash_table_find(hash_table, 22222, &value) != 0) return 1;
	if (value != 922222) return 1;
	if (hash_table_find(hash_table, 33333, &value) != 0) return 1;
	if (value != 933333) return 1;
	if (hash_table_find(hash_table, 88888, &value) != 1) return 1;
	hash_table_destruct(hash_table);
	return 0;
}

int test3()
{
	/* delete */
	int value = 0;
	hash_table_t* hash_table = hash_table_construct(7);
	hash_table_add(hash_table, 11111, 911111);
	hash_table_del(hash_table, 11111);
	if (hash_table_find(hash_table, 11111, &value) != 1) return 1;
	hash_table_destruct(hash_table);
	return 0;
}
